package com.youlai.boot.system.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.boot.system.enums.YesNoEnum;
import com.youlai.boot.system.model.entity.LpsOrderDownload;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.boot.system.model.query.LpsOrderDownloadQuery;
import com.youlai.boot.system.model.vo.LpsOrderDownloadVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 下载记录Mapper接口
 *
 * @author youlaitech
 * @since 2025-08-10 19:52
 */
@Mapper
public interface LpsOrderDownloadMapper extends BaseMapper<LpsOrderDownload> {

    /**
     * 获取下载记录分页数据
     *
     * @param page 分页对象
     * @param queryParams 查询参数
     * @return
     */
    Page<LpsOrderDownloadVO> getLpsOrderDownloadPage(Page<LpsOrderDownloadVO> page, LpsOrderDownloadQuery queryParams);

    /**
     *
     * @param orderId
     * @param userId
     * @return
     */
    default LpsOrderDownload getLpsOrderDownload(Long orderId, Long userId){
        LambdaQueryWrapper<LpsOrderDownload> lqw = new LambdaQueryWrapper<>();
        lqw.eq(LpsOrderDownload::getOrderId, orderId)
                .eq(LpsOrderDownload::getUserId, userId);
        return this.selectOne(lqw);
    }

    /**
     *
     * @param orderId
     * @param userIds
     */
    default List<LpsOrderDownload> getDownloadList(Long orderId, List<Long> userIds){
        return this.selectList(new LambdaQueryWrapper<LpsOrderDownload>()
                .eq(LpsOrderDownload::getOrderId, orderId)
                .eq(LpsOrderDownload::getIsDownload, YesNoEnum.YES.getType())
                .in(LpsOrderDownload::getUserId, userIds));
    }

    void deleteByOrderIds(@Param("orderIds") List<Long> orderIds);
}
